﻿@using MyData.Dto;
@{
    ViewBag.Title = "用户列表";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/UI/js/select-ui.min.js"></script>
<script src="~/Content/plupload/plupload.full.min.js"></script>
<script type="text/javascript">
    $(function () {
        fnUploadImg("updatefile-btn", "loadXls");
        $(".select3").uedSelect({
            width: 330
        });
    })

</script>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">用户管理</a></li>
    </ul>
</div>

<div class="formbody">
    <ul class="seachform">
        <li>
            <label>部门名称:</label>
            <div class="vocation">
                <select class="select3" id="DepartId" style="width:350px">
                    <option value="00000000-0000-0000-0000-000000000001">全部</option>
                    @{
                        List<DepartDto> list = (List<DepartDto>)ViewBag.Departs;
                        foreach (var item in list)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    }

                </select>
            </div>
        </li>
        <li>
            <label>员工姓名:</label><input name="" type="text" class="dfinput" id="NickName" />
        </li>
    </ul>
    <ul class="seachform">
        <li>
            <label>排序字段:</label>
            <div class="vocation" style="width:347px">
                <select class="select3" id="OrderName">
                    <option value="0" selected>时间</option>
                    <option value="1">部门</option>
                    <option value="2">姓名</option>
                </select>
            </div>
        </li>
        <li>
            <label>排列顺序:</label>
            <div class="vocation" style="width:347px">
                <select class="select3" id="OrderType">
                    <option value="0" selected>倒序</option>
                    <option value="1">升序</option>
                </select>
            </div>
        </li>
    </ul>
    <ul class="seachform">
        <li>
            <label>审核操作:</label>
            <div class="vocation" style="width:347px">
                <select class="select3" id="NeedConfirm">
                    <option value="99" selected>全部</option>
                    <option value="0">审核通过</option>
                    <option value="1">待审核</option>
                </select>
            </div>
        </li>
        <li>

            <input name="" id="ok" type="button" class="scbtn" value="查询" />

            <input name="" id="add" type="button" class="scbtn" value="新建用户" />

            <input name="" id="updatefile-btn" type="button" class="scbtn" value="批量添加" />

            <input name="" id="deleteBat" type="button" class="scbtn" value="批量删除" />
        </li>
    </ul>
    <ul class="seachform">
        <li>
            文件格式:技术部_潘景树_1011.jpg
        </li>
    </ul>
</div>
<div class="table-content">
    <table id="table" class="tablelist"></table>
</div>

<script type="text/javascript">
    $(function () {
        var $table = $('#table'), $ok = $('#ok');
        $ok.click(function () {
            $table.bootstrapTable('refresh');
        });
        function queryParams(params) {
            $('#toolbar').find('input[name]').each(function () {
                params[$(this).attr('name')] = $(this).val();
            });
            params["NeedConfirm"] = $("#NeedConfirm").val();
            params["NickName"] = $("#NickName").val();
            params["DepartId"] = $("#DepartId").val();
            params["OrderName"] = $("#OrderName").val();
            params["OrderType"] = $("#OrderType").val();
            return params;
        }
        function responseHandler(res) {

            return res.rows;
        }
        $('#table').bootstrapTable({
            url: '/UserInfo/GetStudents',
            //url: '/api/Document/GetList',
            pagination: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 50,                       //每页的记录行数（*）
            pageList: [10],        //可供选择的每页的行数（*）
            //search: true,   //是否显示表格搜索，此搜索是客户端搜索
            striped: true,
            queryParams: queryParams,
            //responseHandler:responseHandler,
            toolbar: "#toolbar",
            columns: [
                {
                    checkbox: true
                }, {
                    field: 'Number',
                    title: '序号',
                    align: 'center',
                    width: 50,
                    formatter: function (value, row, index) {
                        //return index + 1;
                        var pageSize = $('#table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                }, {
                    field: 'WorkNum',
                    title: '员工编号'
                },
            {
                field: 'DepartName',
                title: '部门名称'
            }, {
                field: 'NickName',
                title: '员工姓名'
            }, {
                field: 'RoleName',
                title: '所属职位'
            },
            {
                field: 'CreatedTimeStr',
                title: '提交时间'
            }, {
                field: 'Id',
                title: '操作',
                formatter: function (value, row) {
                    if (row.NeedConfirm == 0) {
                        return '<a  onclick="fnEidt(\'' + value + '\')" class="tablelink">修改</a>   <a onclick="fnDelete(\'' + value + '\')" class="tablelink">删除</a>';
                    }
                    else {
                        return '<a  onclick="fnConfirm(\'' + value + '\')" class="tablelink">审核</a>     <a  onclick="fnEidt(\'' + value + '\')" class="tablelink">修改</a>   <a onclick="fnDelete(\'' + value + '\')" class="tablelink">删除</a>';
                    }
                 

                }
            }, ]
        });

        $("#add").click(function () {

            window.layer.open({
                type: 2,
                area: ['1000px', '550px'],
                fixed: true, //不固定
                maxmin: true,
                content: '@Url.Action("UserView","UserInfo")'
            });
        })
        $("#deleteBat").click(function () {
            layer.confirm('确定批量删除吗？', {
                btn: ['确定', '取消'] //按钮
            }, function (index) {
                var temp = $('#table').bootstrapTable("getSelections");
                var array = [];
                for (var i = 0; i < temp.length; i++) {
                    array.push(temp[i].Id);
                }
                $.post("../UserInfo/UserInfoDelete", { Ids: array }, function (result) {
                    if (result.state == 1) {
                        layer.msg('操作成功');
                        layer.close(index);
                        $("#table").bootstrapTable('refresh');
                    }
                    else {
                        layer.msg(result.message);
                    }
                })
            }, function (index) {
                layer.close(index);
            });

        })

    })

    function fnEidt(id) {
        window.layer.open({
            type: 2,
            area: ['1000px', '550px'],
            fixed: true,
            maxmin: true,
            content: '@Url.Action("UserView","UserInfo")?id=' + id
        });
    }
    function fnDelete(id) {
        layer.confirm('确定删除吗？', {
            btn: ['确定', '取消'] //按钮
        }, function (index) {
            var array = [];
            array.push(id)
            $.post("../UserInfo/UserInfoDelete", { Ids: array }, function (result) {
                if (result.state == 1) {
                    layer.msg('操作成功');
                    layer.close(index);
                    $("#table").bootstrapTable('refresh');
                }
                else {
                   layer.msg(result.message);
                }
            })
        }, function (index) {
            layer.close(index);
        });

    }
    function fnUploadImg(btnId, containerId) {
        var uploader = new plupload.Uploader({ //实例化一个plupload上传对象
            browse_button: btnId,
            url: '@Url.Action("BatchUser", "UserInfo")',
            //container: document.getElementById(containerId),
            flash_swf_url: '/Content/plupload/Moxie.swf',
            silverlight_xap_url: '/Content/plupload/Moxie.xap',
            filters: {
                mime_types: [ //只允许上传图片文件和rar压缩文件
                    { title: "Image files", extensions: "jpg,gif,png" }
                ],
                max_file_size: '20000kb', //最大只能上传20000kb的文件
                prevent_duplicates: false //不允许队列中存在重复文件
            },
            resize: {
                crop: false,
                quality: 60,
                preserve_headers: false
            },
            multipart_params: {}//参数
        });
        uploader.init(); //初始化
        uploader.bind('FilesAdded', function (uploader, files) {
            uploader.start();
        });
        uploader.bind('FileUploaded', function (uploader, file, responseObject) {
            var dom = document.getElementById(file.id)
            var response = $.parseJSON(responseObject.response);
            if (response.state == 1) {
                //$("#" + imgId).attr("src", response.data);
                layer.msg('操作成功');
                $("#table").bootstrapTable('refresh');
            } else {
                layer.msg(response.message);
            }
        })
    }

    function fnConfirm(id)
    {
        $.post("../UserInfo/ConfirmUserInfo", { Id: id }, function (result) {
            if (result.state == 1) {
                layer.msg('操作成功');
                $("#table").bootstrapTable('refresh');
            }
            else {
                layer.msg(result.message);
            }
        })
    }

</script>